<template>
	<uni-popup ref="stepPopup" type="center">
		<view class="content" @click.stop="''">
			<view class="title">
				{{content.popupTitle}}
				<text class="iconfont icon-guanbi" @click="close"></text>
			</view>
			<!-- input -->
			<block v-if="content.inputJudge">
				<view class="secondTitle">{{content.popupSecondaryTitle}}</view>
				<view class="inputtext" >
					<input type="text" v-model="content.inputText" :placeholder="content.popupInput"/>
				</view>
			</block>
			<block v-if="content.imgJudge">
				<view class="secondTitle">{{content.popupSecondaryTitle}}</view>
				<view class="box">
					<image  class="codeImage"
					 v-for="(item,index) in content.img" :key="index" :src="$util.img(item)" mode=""></image>
					<view class="codeImage"  @click="addimg" v-if="content.name != 'addCode'">
						<text class="iconfont icon-tianjiatianchong"></text>
					</view>
					<view class="codeImage"  @click="addimg" v-else-if="content.img.length == 0">
						<text class="iconfont icon-tianjiatianchong"></text>
					</view>
				</view>
			</block>
			<!-- textarea -->
			<view class="secondTitle">步骤说明</view>
			<view class="textareatext">
				<textarea type="text"
				 placeholder-style="font-weight:bold" 
				 v-model="content.textarea"
				 :placeholder="content.popupTextarea"/>
			</view>
			
			<!-- 确定 -->
			<button type="default" class="determine" @click="determine">确定</button>
		</view>
	</uni-popup>
</template>

<script>
	export default{
		data(){
			return {
				content:{},
				type:'add'//判断是编辑还是添加
			}
		},
		methods:{
			// 打开弹窗
			open(item,type){
				this.type = type;
				this.content = JSON.parse(item);
				console.log("this.ontent",this.content)
				this.$refs.stepPopup.open();
				return false;
				
			},
			//关闭弹窗
			close(){
				this.$refs.stepPopup.close();
			},
			//确定
			determine(){
				this.content.checked = true;
				this.$emit('determine',this.content,this.type)
				this.close()
			},
			//添加图片
			addimg(){
				this.$util.selectImage({
					num:1,
					success:(res)=>{
						if(res.judge){
							let url = JSON.parse(res.data).data[0].filepath;
							this.content.img.push(url)
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 680rpx;
		margin:0 30rpx;
		padding: 48rpx 50rpx 74rpx;
		box-sizing:border-box;
		background: #FFFFFF;
		border-radius: 20rpx;
		font-family: PingFangSC-bold;
		z-index: 99999;
		.title{
			text-align: center;
			font-size: 32rpx;
			font-weight: bold;
			position: relative;
			margin-bottom: 40rpx;
			.iconfont{
				position: absolute;
				top: 50%;
				right: 0;
				transform: translateY(-50%);
				font-size: 28rpx;
				color: #888888;
			}
		}
		.secondTitle{
			font-size: 28rpx;
			color: #101010;
			font-weight: bold;
			margin-bottom: 20rpx;

		}
		.box{
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			height: 250rpx;
			overflow-y: scroll;
			image{
				margin-right: 20rpx;
			}
		}
		.inputtext{
			width: 100%;
			height: 68rpx;
			background: #EFF2F7;
			border-radius: 16rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-bottom:48rpx;
			input{
				width: 90%;
				height: 90%;
				font-size: 24rpx;
				text-align: center;
			}
		}
		.textareatext{
			width: 100%;
			height: 240rpx;
			background: #EFF2F7;
			border-radius: 16rpx;
			padding: 34rpx 36rpx;
			box-sizing: border-box;
			margin-bottom:48rpx;
			textarea{
				width: 100%;
				height: 100%;
				font-size: 24rpx;
				line-height: 1.4;
			}
		}
		.determine{
			width: 100%;
			height: 80rpx;
			text-align: center;
			line-height: 80rpx;
			font-size: 28rpx;
			background: $uni-tabbar-hovercolor;
			margin-top: 60rpx;
			color: #FFFFFF;
			border-radius:80rpx;
		}
		.codeImage{
			width: 240rpx;
			height: 240rpx;
			border-radius: 16rpx;
			background: #EFF2F7;
			display: flex;
			align-items: center;
			justify-content: center;
			color:$uni-tabbar-hovercolor;
			margin-bottom: 40rpx;
			.iconfont{
				font-size: 60rpx !important;
			}
		}
	}
	
	/deep/ .uni-popup__wrapper{
		z-index: 9999;
	}
</style>
